<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Results extends AdminController {

	function __construct() { 
		parent::__construct();
		$this -> load -> model("Audit_model");
		$this -> load -> model("User_model");
		$this -> load -> model("Admin_model");
		$this->load ->library('ProjectService/results_service');
		$this->load ->library('ProjectService/data_service');
	}
	// 查询个人成果页面
	public function personView() {
		$connar['where']=$this->sqlEscape("is_del=??",array(CommonWhether::Not[XPHEnum::Value]));
		$role = explode(',', getSess()['sub_role_id']);
        array_push($role, getSess()['role_id']);

        if(in_array(WebRole::SchoolLeader[XPHEnum::Value], $role) || in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role) || in_array(WebRole::Admin[XPHEnum::Value], $role)){
        	$connar['where'].=' and 1=1';
        }else if(in_array(WebRole::BranchPresident[XPHEnum::Value], $role) || in_array(WebRole::BranchManage[XPHEnum::Value], $role)){
        	$connar['where'].=$this->sqlEscape(' and dept_name=??',array(getSess()['dept_name']));
        }else{
        	$connar['where'].=$this->sqlEscape(' and username=??',array(getSess()['username']));
        }
		$data['user']=$this->User_model->get_list_full($connar);
		foreach ($data['user'] as $k => $v) {
			$data['user'][$k]['identity_id']= $v['type'];
			$data['user'][$k]['identity']=(new CommonIdentity)->show($v['type']);
		}
		$this -> load -> view('admin/result_person',$data);
	}
	// 获取个人成果数据
	public function personData()
	{
		$param=$_POST;
		$data=$this->results_service->personData($param);
		exit(retJson('成果数据', true, $data));
	}

	// 导出个人成果
	public function personDataExport()
	{
		$param=$_POST;
		if($param['name']==-1){
			exit(retJson('请选择成果人',false));
		}
		$data=$this->results_service->personDataExport($param);
		exit($data);
	}

	// 查询二级单位成果页面
	public function deptView() {
	
		$role = explode(',', getSess()['sub_role_id']);
        array_push($role, getSess()['role_id']);

        if(in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)||in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role)){
	        $deptlist =	array();
			foreach ((new Dept())->getAll() as $k => $v) {
					$deptlist[$k]['dept_id'] = $v[XPHEnum::Value];
					$deptlist[$k]['dept_name'] = $v[XPHEnum::Caption];
			}
			$data['dept']= $deptlist;
        }else{
        	$connar['items']="dept_name";
			$connar['groupby']="dept_name";
			$connar['where']=$this->sqlEscape("status=??",array(CommonStatus::UnDeleted[XPHEnum::Value]));
			$connar['where'].=" and dept_name in('交通分院','商贸分院','建筑工程分院','机械工程分院','电气电子工程分院','设计与艺术分院','财经分院','鉴湖分院','人文社科部','公共基础教学部（体育部）、马克思主义学院','职能管理部','外单位','校领导','机电分院')";

        	 if(in_array(WebRole::Admin[XPHEnum::Value], $role) || in_array(WebRole::Manage[XPHEnum::Value], $role) || in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)|| in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role)){
	        	$connar['where'].=' and 1=1';
	        }else if(in_array(WebRole::BranchPresident[XPHEnum::Value], $role) || in_array(WebRole::BranchManage[XPHEnum::Value], $role)){
	        	$connar['where'].=$this->sqlEscape(" and dept_name=??",array(getSess()['dept_name']));
	        	$data['show_dept']=getSess()['dept_name'];
	        }else{
	        	$connar['where'].=" and 1<>1";
	        	$data['show_dept']=getSess()['dept_name'];
	        }
	    	$data['dept']=$this->Admin_model->get_list_full($connar);

        }
		$this -> load -> view('admin/result_dept',$data);
	}
	// 获取二级单位成果数据
	public function deptData()
	{
		$param=$_POST;
		if($param['search_type']==1){
			$data=$this->results_service->deptData($param);
			exit(retJson('成果数据', true, $data));
		}else{
			$data=$this->data_service->getDatas($param);
			exit($data);
		}
		
		
	}

	// 导出二级单位成果
	public function deptDataExport()
	{
		$param=$_POST;
		$data=$this->results_service->deptDataExport($param);
		exit($data);
	}

	// 查询学校成果页面
	public function schoolView() {
		$role = explode(',', getSess()['sub_role_id']);
        array_push($role, getSess()['role_id']);

        if(in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)||in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role)){
        	$deptlist =	array();
			foreach ((new Dept())->getAll() as $k => $v) {
					$deptlist[$k]['dept_id'] = $v[XPHEnum::Value];
					$deptlist[$k]['dept_name'] = $v[XPHEnum::Caption];
			}
			$data['dept']= $deptlist;
        }else{
			$connar['items']="dept_name";
			$connar['groupby']="dept_name";
			$connar['where']=$this->sqlEscape("status=??",array(CommonStatus::UnDeleted[XPHEnum::Value]));
			$connar['where'].=" and dept_name in('交通分院','商贸分院','建筑工程分院','机械工程分院','电气电子工程分院','设计与艺术分院','财经分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导','机电分院')";
			$data['dept']=$this->Admin_model->get_list_full($connar);

        }			

		$this -> load -> view('admin/result_school',$data);
	}
	// 获取学校成果数据
	public function schoolData()
	{
		$param=$_POST;
		if($param['search_type']==1){
			$data=$this->results_service->schoolData($param);
			exit(retJson('成果数据', true, $data));
		}else{
			$data=$this->data_service->getDatas1($param);
			exit($data);
		}
		
		
	}

	// 导出学校成果
	public function schoolDataExport()
	{
		$param=$_POST;
		$data=$this->results_service->schoolDataExport($param);
		exit($data);
	}

	// 查询所有成果页面
	public function alllView() {
		$role = explode(',', getSess()['sub_role_id']);
        array_push($role, getSess()['role_id']);

        if(in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)||in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role)){
        	$deptlist =	array();
			foreach ((new Dept())->getAll() as $k => $v) {
					$deptlist[$k]['dept_id'] = $v[XPHEnum::Value];
					$deptlist[$k]['dept_name'] = $v[XPHEnum::Caption];
			}
			$data['dept']= $deptlist;
        }else{

	        $connar['items']="dept_name";
			$connar['groupby']="dept_name";
			$connar['where']=$this->sqlEscape("status=??",array(CommonStatus::UnDeleted[XPHEnum::Value]));
			$connar['where'].=" and dept_name in('交通分院','商贸分院','建筑工程分院','机械工程分院','电气电子工程分院','设计与艺术分院','财经分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导','机电分院')";
			$data['dept']=$this->Admin_model->get_list_full($connar);
        }				

		$data['user']=$this->User_model->get_list(array('is_del'=>CommonWhether::Not[XPHEnum::Value]));
		foreach ($data['user'] as $k => $v) {
			$data['user'][$k]['identity_id']= $v['type'];
			$data['user'][$k]['identity']=(new CommonIdentity)->show($v['type']);
		}

		$this -> load -> view('admin/result_all',$data);
	}	

	
}